package com.frogs.ucenter.v1.service.impl;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.frogs.system.web.api.request.Request;
import com.frogs.system.web.api.response.Response;
import com.frogs.system.web.exception.ServiceOperationException;
import com.frogs.ucenter.dao.TagUserRelationDao;
import com.frogs.ucenter.entity.TagUserRelation;
import com.frogs.ucenter.v1.request.TagUserRelationListRequest;
import com.frogs.ucenter.v1.response.PageListResponse;
import com.frogs.ucenter.v1.service.TagUserRelationService;
import com.frogs.ucenter.v1.util.ApiConstants;

@Transactional(propagation=Propagation.REQUIRED, rollbackFor=Exception.class) 
@Service(ApiConstants.VERSION + "tagUserRelationService")
public class TagUserRelationServiceImpl extends UserBaseServiceImpl implements TagUserRelationService {
	
	Logger log = LoggerFactory.getLogger(TagUserRelationServiceImpl.class);
	
    @Resource
    private TagUserRelationDao tagUserRelationDao;

	@Override
	public Response listUserTags(Request request)  throws Exception {
		try {
			TagUserRelationListRequest turgRequest = (TagUserRelationListRequest) request;
			PageListResponse<Map<String, Object>> turgResponse = new PageListResponse<Map<String, Object>>(); 
			int userId = turgRequest.getUserId();
			turgResponse.setList(listUserTags(userId));
			return turgResponse;
		} catch(Exception e) {
			log.error("func[{}] request[{}] exception[{}] desc[fail]",
					new Object[] { this.getClass().getName() +"."+Thread.currentThread().getStackTrace()[1].getMethodName(),
						request,Arrays.deepToString(e.getStackTrace()) });
			throw new ServiceOperationException("请求处理失败：" + e.getMessage());
		}
	}
	
	@Override
	public void batchInsert(List<TagUserRelation> tagUsers) {
		tagUserRelationDao.batchInsert(tagUsers);
	}
	
}